//检查两棵树是否相同
class Solution3 {
    class TreeNode{
        public int val;
        public TreeNode left;
        public TreeNode right;

        public TreeNode(int val) {
            this.val = val;
        }
    }
    public boolean isSameTree(TreeNode p, TreeNode q) {
        if(p==null&&q!=null
           ||p!=null&&q==null){
            return  false;
        }
        if(p==null&&q==null){
            return true;
        }
        if(p.val!=q.val){
            return false;
        }
        return isSameTree(q.left,p.left)
                &&isSameTree(q.right,p.right);
    }
}